<script setup lang="ts">
import { useECharts } from '@/hooks/use-echarts'

const props = defineProps({
  activeTab: {
    type: String,
    default: ''
  }
})

const chartRef = ref()
const { setOptions, getInstance } = useECharts({
  el: chartRef,
})

onMounted(() => {
  setOptions({
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        lineStyle: {
          width: 1,
          color: '#019680',
        },
      },
    },
    grid: { left: 0, right: 0, top: 10, bottom: 0, containLabel: true },
    xAxis: {
      type: 'category',
      data: [
        '1月',
        '2月',
        '3月',
        '4月',
        '5月',
        '6月',
        '7月',
        '8月',
        '9月',
        '10月',
        '11月',
        '12月',
      ],
    },
    yAxis: {
      type: 'value',
      max: 8000,
      splitNumber: 4,
    },
    series: [
      {
        data: [3000, 2000, 3333, 5000, 3200, 4200, 3200, 2100, 3000, 5100, 6000, 3200, 4800],
        type: 'bar',
        barMaxWidth: 80,
      },
    ],
  })
})

watch(() => props.activeTab, () => {
  if (!getInstance()) {
    nextTick(() => {
      setOptions()
    })
  }
})
</script>

<template>
  <div
    ref="chartRef"
    class="chart"
  ></div>
</template>

<style scoped lang="less">
.chart {
  height: 100%;
}
</style>
